package org.java.srb.core.controller.admin;

import org.java.srb.common.result.Result;
import org.java.srb.core.pojo.entity.IntegralGrade;
import org.java.srb.core.service.IntegralGradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author hu
 * @version 1.0
 * @date 2021/4/18 0018 下午 12:51
 * @description 积分等级表
 */
@CrossOrigin
@RestController
@RequestMapping("/admin/core/integralGrade")
public class AdminIntegralGradeController {

    @Autowired
    private IntegralGradeService integralGradeService;

    @RequestMapping("/list")
    public Result list() {
        List<IntegralGrade> integralGradeList = integralGradeService.list();
        return Result.success().data("list",  integralGradeList);
    }


    @PostMapping("/delete/{id}")
    public Result deleteById(@PathVariable("id") String id) {
        integralGradeService.deleteById(id);
        return  Result.success();
    }

    @GetMapping("/getGrade")
    public Result getGrade() {
        return Result.success().data("data", 1);
    }

    @GetMapping("/getClass")
    public Result getClassByGrade(String grade) {
        Map<String, List<String>> gradeMap = new HashMap<>(4);
        gradeMap.put("1", Arrays.asList("1", "2", "3", "4"));
        gradeMap.put("2", Arrays.asList("5", "6", "7", "8"));
        return Result.success().data("list", gradeMap.get(grade));
    }
}
